﻿package net.sealuitk.containers 
{
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import net.sealuitk.Container;
	import net.sealuitk.UIConst;
	
	// TODO: Flowpanels reflow after size change
	
	/**
	 * ...
	 * @author mkn
	 */
	public class FlowHorizontal extends Container
	{
		protected var column:Column;
		protected var rows:Array = new Array();
		protected var currentRow:Row;
		
		public function FlowHorizontal(Name:String, Width:Number, Height:Number, AlignHorizontal:String = UIConst.ALIGN_LEFT, AlignVertical:String = UIConst.ALIGN_TOP ) {
			super(Name, Width, Height);
			alignVertical = AlignVertical;
			alignHorizontal = AlignHorizontal;
			column = new Column("HFlow Column", Width, Height, UIConst.ALIGN_LEFT, alignVertical );
			super.add(column);
			nextRow();
		}
		
		override public function add(newContent:*, floating:Boolean = false ):void {
			if (floating) add(newContent, true);
			else {
				if (sizeSet) {
					if ( ( currentRow.width + contentPadding.x + newContent.width ) 
						> ( this.width - (padding.left + padding.right) ) ) {
						nextRow();	
					}
				}
				currentRow.add(newContent);
				currentRow.update();
				column.update();
				update();
			}
		}
		
		public function nextRow():void {
			rows.push(new Row("Row " + ( rows.length - 1), 0, 0, alignHorizontal, UIConst.ALIGN_CENTER) );
			currentRow = rows[ rows.length -1 ];
			currentRow.setContentPadding(contentPadding.x, contentPadding.y);
			column.add( currentRow );
		}
		
		override public function setContentPadding(horizontal:Number, vertical:Number):void {
			super.setContentPadding(horizontal, vertical);
			super.updateFixed();
			
			for (var i:int = 0; i < contentFixed.length ; i++) {
				contentFixed[i].setContentPadding(horizontal, vertical);
			}
			
			column.setContentPadding( horizontal , vertical );
		}
	}

}